#include <QApplication>
#include <QQmlContext>
#include <QQmlApplicationEngine>
#include <QtQuickControls2/QQuickStyle>
#include "src/ScreenshotHelper.h"
#include "src/confighelper.h"
#include "src/pixmapprovider.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    Confighelper::getInstance()->init();

    QQuickStyle::setStyle("Universal");

    QQmlApplicationEngine engine;
    ScreenshotHelper Screenshot;
    Screenshot.setEngine(&engine);
    engine.rootContext()->setContextProperty("g_screenShot", &Screenshot);
    engine.rootContext()->setContextProperty("g_configHelper", Confighelper::getInstance());
    engine.addImageProvider("pixmap", new PixmapProvider);
    QObject::connect(
        &engine,
        &QQmlApplicationEngine::objectCreationFailed,
        &app,
        []() { QCoreApplication::exit(-1); },
        Qt::QueuedConnection);
    engine.loadFromModule("qscreenshot", "Main");

    app.setQuitOnLastWindowClosed(false);

    app.setWindowIcon(QIcon(":/image/res/favicon.ico"));

    return app.exec();
}
